<<<<<<< HEAD
import { getToken, setToken, removeToken } from '@/utils/auth'
import { login, getInfo, getuserimg } from '@/api/user'
=======
import { getToken, setToken } from '@/utils/auth'
import { login, userinfo, userphoto } from '@/api/user'
>>>>>>> a65ad1838d1975b3ee62005f8061eb6c31417121

export default {
  namespaced: true,
  state: () => {
    return {
      token: getToken() || '',
<<<<<<< HEAD
      userfrom: {}
=======
      userinfo: {

      }
>>>>>>> a65ad1838d1975b3ee62005f8061eb6c31417121
    }
  },
  mutations: {
    settoken(state, data) {
      state.token = data
<<<<<<< HEAD
    },
    setuserinfo(state, data) {
      state.userfrom = data
=======
      setToken(data)
    },
    setuserinfo(state, data) {
      state.userinfo = data
>>>>>>> a65ad1838d1975b3ee62005f8061eb6c31417121
    }

  },
  actions: {
    async dologin(context, data) {
<<<<<<< HEAD
      const datas = await login(data)

      context.commit('settoken', datas.data)
      console.log(datas)
      setToken(datas.data)
    },
    async getuserinfo(context, data) {
      const { data: res } = await getInfo()

      const { data: rs } = await getuserimg(res.userId)
      const obj = { ...res, ...rs }
      context.commit('setuserinfo', obj)
    },
    loginout(context, data) {
      context.commit('setuserinfo', {})
      context.commit('settoken', ' ')

      removeToken()
=======
      const { data: res } = await login(data)
      context.commit('setToken', res)
    },
    async getuserinfo(context, data) {
      const { data: res } = await userinfo(data)
      const { data: re } = await userphoto(res.userId)
      console.log(re.staffPhoto)
      const obj = { ...res, ...re }
      context.commit('setuserinfo', obj)
    },
    logout(context) {
      context.commit('setuserinfo', { })
      context.commit('setToken', '')
>>>>>>> a65ad1838d1975b3ee62005f8061eb6c31417121
    }

  },
  getters: {}
}
